package com.sskj.bibi.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.bibi.bean.CoinFee;
import com.sskj.bibi.http.HttpConfig;
import com.sskj.bibi.ui.fragment.PankouFragment;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.bean.StockCoinBean;
import com.sskj.lib.bean.WSFiveBean;
import com.sskj.lib.http.JsonCallBack;

import java.util.ArrayList;
import java.util.List;


public class PankouFragmentPresenter extends BasePresenter<PankouFragment> {

    public void getProduct(String code) {
        httpService.getProduct(code)
                .tag(this)
                .execute(new JsonCallBack<HttpData<List<StockCoinBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<StockCoinBean>>> response) {
                        HttpData<List<StockCoinBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            if (httpData.getData().size() > 0) {
                                mView.updateTitle(httpData.getData().get(0));
                            }
                        }
                    }
                });
    }

    public void getPankou(String code) {
        httpService.getPankou(code)
                .tag(this)
                .execute(new JsonCallBack<HttpData<List<WSFiveBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<WSFiveBean>>> response) {
                        HttpData<List<WSFiveBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            if (httpData.getData() != null && httpData.getData().size() > 0 && httpData.getData().get(0) != null) {
                                WSFiveBean wsFiveBean = httpData.getData().get(0);
                                mView.updateFive(wsFiveBean);
                            } else {
                                WSFiveBean wsFiveBean = new WSFiveBean();
                                wsFiveBean.setCode(code);
                                wsFiveBean.setAsks(new ArrayList<>());
                                wsFiveBean.setBids(new ArrayList<>());

                                mView.updateFive(wsFiveBean);
                            }
                        }
                    }
                });
    }

//    public void getRate(String code) {
//        httpService.getCoinFee(code)
//                .execute(new JsonCallBack<HttpData<CoinFee>>() {
//                    @Override
//                    public void onSuccess(Response<HttpData<CoinFee>> response) {
//                        HttpData<CoinFee> httpData = response.body();
//                        if (httpData.getStatus() == HttpConfig.OK) {
//                            mView.updateFee(httpData.getData());
//                        }
//                    }
//                });
//    }
}
